package org.example;

import java.util.HashMap;
import java.util.Map;

class wordPattern {
    public static boolean wordPattern(String pattern, String s) {
        int len = pattern.length();
        String[] arr = s.split(" ");
        int sLen = arr.length;

        if(len!=sLen){
            return false;
        }

        Map<Character,String> map = new HashMap<>();
        for(int i=0;i<len;i++){
            char c = pattern.charAt(i);
            if(!map.containsKey(c)){
                map.put(c,arr[i]);
            }else{
                if(arr[i]!=map.get(c)){
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        boolean is =  wordPattern("abba","dog cat cat dog");
        System.out.println(is);
    }
}